package com.etb.wisdom.eframe.auth.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Service;

import com.etb.core.service.ETBService;
import com.etb.wisdom.eframe.auth.service.PartyResService;

@Service
public class PartyResServiceImpl extends ETBService implements PartyResService {
	
	@Override
	public List getResources(Set roleIds) {
		if(roleIds != null && roleIds.size() > 0) {
			Map<String,Object> params = new HashMap<String, Object>();
			params.put("partyids", roleIds.toArray());
			return service.queryByNamedsql("query.eframe.framework.res.getResources", params, "funcuri");
		} else {
			return new ArrayList<String>();
		}
	}

//	@Override
//	public List getUserRoleIds(EtbUser user) {
//		//用户角色
//		EtbPartyAuth authTemplate = new EtbPartyAuth();
//		authTemplate.setPartyid(user.getId());
//		authTemplate.setPartytype(PartyType.user.toString());
//		authTemplate.setAuthtype(AuthType.role.toString());
//		List roleIds = service.querySpecifiedProperty(authTemplate, "authid");
//		Set roleIdSet = new HashSet();
//		roleIdSet.addAll(roleIds);
//		//用户关联员工部分
//		OrgEmployee emp = new OrgEmployee();
//		emp.setUserid(user.getLoginname());
//		service.extend(emp);
//		if(emp.exist()) {
//			//员工角色
//			authTemplate = new EtbPartyAuth();
//			authTemplate.setPartyid(emp.getId());
//			authTemplate.setPartytype(PartyType.employee.toString());
//			authTemplate.setAuthtype(AuthType.role.toString());
//			roleIdSet.addAll(service.querySpecifiedProperty(authTemplate, "authid"));
//			//员工所在岗位及上级岗位
//			OrgPosition position = new OrgPosition();
//			position.setId(emp.getPositionid());
//			service.extend(position);
//			List<String> positionIds = new ArrayList<String>();
//			while(position.getId() != null) {
//				positionIds.add(position.getId());
////				authTemplate = new EtbPartyAuth();
////				authTemplate.setPartyid(emp.getPositionid());
////				authTemplate.setPartytype(PartyType.position.toString());
////				authTemplate.setAuthtype(AuthType.role.toString());
////				roleIds.addAll(service.queryOnlyProperty(authTemplate, "authid"));
//				if(position.getUplevelid() != null) {
//					OrgPosition uplevelPosition = new OrgPosition();
//					uplevelPosition.setId(position.getUplevelid());
//					service.extend(uplevelPosition);
//					position = uplevelPosition;
//				}
//			}
//			//岗位所在机构角色
//			OrgOrganization org = new OrgOrganization();
//			org.setId(position.getOrgid());
//			service.extend(org);
//			List<String> orgIds = new ArrayList<String>();
//			while(org.getId() != null) {
//				orgIds.add(org.getId());
//				if(org.getUplevelid() != null) {
//					OrgOrganization uplevelOrg = new OrgOrganization();
//					uplevelOrg.setId(org.getUplevelid());
//					service.extend(uplevelOrg);
//					org = uplevelOrg;
//				}
//			}
//			//用户所在机构角色
//			org = new OrgOrganization();
//			org.setId(emp.getOrgid());
//			service.extend(org);
//			while(org.getId() != null) {
////				authTemplate = new EtbPartyAuth();
////				authTemplate.setPartyid(emp.getOrgid());
////				authTemplate.setPartytype(PartyType.organization.toString());
////				authTemplate.setAuthtype(AuthType.role.toString());
////				roleIds.addAll(service.queryOnlyProperty(authTemplate, "authid"));
//				orgIds.add(org.getId());
//				if(org.getUplevelid() != null) {
//					OrgOrganization uplevelOrg = new OrgOrganization();
//					uplevelOrg.setId(org.getUplevelid());
//					service.extend(uplevelOrg);
//					org = uplevelOrg;
//				}
//			}
//		}
//		
//		
//		return roleIds;
//	}
}
